package com.lean.android.projecttemplate.startup

import android.content.Context
import androidx.startup.Initializer
import com.lean.android.projecttemplate.BuildConfig
import com.lean.android.projecttemplate.appModule
import com.lean.android.repository.repositoryModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidFileProperties
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext
import org.koin.core.logger.Level
import org.koin.dsl.module
import timber.log.Timber

class KoinInitializer : Initializer<Unit> {

    override fun create(context: Context) {
        Timber.d("init koin.")
        GlobalContext.startKoin {
            androidLogger(if (BuildConfig.DEBUG) Level.DEBUG else Level.NONE)
            androidContext(context)
            androidFileProperties("ad_config.properties")
            androidFileProperties("host.properties")
            //todo other module
            modules(appModule, repositoryModule)
        }
    }

    override fun dependencies(): List<Class<out Initializer<*>>> {
        return listOf(CommonComponentInitializer::class.java)
    }
}